﻿
<div ms-controller="tmpmodelview">
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            用户名：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.UserName" data-rules="required" maxlength="50" ms-if="ModelData.ID==0">
            <span ms-if="ModelData.ID!=0">{{ModelData.UserName}}</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            密码：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.Password" maxlength="20">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            真实姓名：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.TrueName" maxlength="20">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            手机号：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.Telephone" maxlength="20">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            角色：
        </label>
        <div class="controls">
            <select class="input-medium input-xfat" ms-duplex="ModelData.RoleID">
                <option ms-repeat-el="RoleData" ms-attr-value="el.ID" ms-attr-selected="ModelData.RoleID==el.ID?'selected':''">{{el.RoleName}}</option>
            </select>
        </div>
    </div>

</div>

<script type="text/javascript">
    var tempmodel = avalon.define({
        $id: "tmpmodelview",
        ModelData: { "ID": "0", "UserName": "", "TrueName": "", "Password": "", "Telephone": "", "RoleID": "" },
        RoleData: [],
        Init: function (ID) {
            if (ID) {
                $.getJSON("/adapi/auth/usermodel/" + ID, function (r) {
                    if (r.error == "") {
                        tempmodel.ModelData = r.result;
                    }

                })
            }

            $.getJSON("/adapi/auth/rolelist", function (r) {
                if (r.error == "") {
                    tempmodel.RoleData = r.result;
                }

            })
        },
        tmpSaveData: function () {

            $.post("/adapi/auth/useradd", tempmodel.ModelData.$model, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");
                    top.ComFunJS.close();
                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }

            })
        }

    });


</script>
